import http from '../http'
import { messageCenter } from '../host'

const API = {
  postCreateMsg: '/api/v1/messageCenter/createMessage',
  getMsgList: '/api/v1/messageCenter/getMessageList',
  getMsgDetail: '/api/v1/messageCenter/getMessageDetail',
  deleteMsg: '/api/v1/messageCenter/deleteMessage',
  getMsgReadStatus: '/api/v1/messageCenter/getTargetIsRead'
}

// 创建消息
export const reqPostCreateMsg = data =>
  http.post(messageCenter + API.postCreateMsg, data).then(res => res.code === 1)

// 获取消息列表
export const reqGetMsgList = params =>
  http
    .get(messageCenter + API.getMsgList, { params })
    .then(res => res.data || [])
    .catch(() => [])

// 获取消息详情
export const reqGetMsgDetail = params =>
  http
    .get(messageCenter + API.getMsgDetail, { params })
    .then(res => res.data || {})
    .catch(() => ({}))

// 删除待发布消息
export const reqDeleteMsg = params =>
  http
    .delete(messageCenter + API.deleteMsg, { params })
    .then(res => res.code === 1)

// 获取消息的查阅状态
export const reqGetMsgReadStatus = params =>
  http
    .get(messageCenter + API.getMsgReadStatus, { params })
    .then(res => res.data || {})
    .catch(() => ({}))
